package com.sunwayhorizo.health.business.clinic.mqa;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;

import com.sunwayhorizo.health.business.base.BaseManager;
import com.sunwayhorizo.health.business.clinic.mqa.query.QADefectQueryLocal;
import com.sunwayhorizo.health.business.dto.PageDTO;
import com.sunwayhorizo.health.business.dto.ResultsDTO;
import com.sunwayhorizo.health.business.dto.clinic.mqa.DefectInfoDTO;
import com.sunwayhorizo.health.business.patad.encounter.query.PatientEncounterQueryLocal;
import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.common.DateUtil;
import com.sunwayhorizo.health.common.ListUtil;
import com.sunwayhorizo.health.common.StrUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ED;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.rim.Act;
import com.sunwayhorizo.health.hl7.rim.ActParticipation;
import com.sunwayhorizo.health.hl7.rim.ControlAct;
import com.sunwayhorizo.health.hl7.rim.PatientEncounter;
import com.sunwayhorizo.health.hl7.rim.Role;
import com.sunwayhorizo.health.hl7.vocabulary.ActClass;
import com.sunwayhorizo.health.hl7.vocabulary.ActMood;
import com.sunwayhorizo.health.hl7.vocabulary.EntityNameUse;
import com.sunwayhorizo.health.hl7.vocabulary.ParticipationType;
import com.sunwayhorizo.health.hl7.vocabulary.RoleCode;
import com.sunwayhorizo.health.hl7.vocabulary.RoleIICode;

@Name("QADefectManager")
@Stateless
public class QADefectManager extends BaseManager implements QADefectManagerLocal
{
    private QADefectQueryLocal defectQueryLocal = (QADefectQueryLocal) Component.getInstance("QADefectQuery");
    private PatientEncounterQueryLocal patientEncounterQueryLocal = (PatientEncounterQueryLocal) Component.getInstance("PatientEncounterQuery");

    @Override
    public ResultsDTO newDefectInfo(DefectInfoDTO defectInfoDTO) throws Hl7Exception
    {
        // 1、判断defectInfoDTO是否为空，为空直接返回
        if (defectInfoDTO == null)
        {
            log.info("defectInfoDTO 为空", defectInfoDTO);
            return getResultsDTO("新增缺陷信息失败,缺陷信息为空", false, null);
        }
        // 2、创建一个缺陷动作
        Act information = getActFactory().newAct(ActClass.INFO, ActMood.DEF, DataTypeUtil.getCE(defectInfoDTO.getDefectTypeCode()), null);
        // 3、给缺陷动作赋值
        convertInformationFromDefectDTO(defectInfoDTO, information);

        // 4、加入参与到缺陷动作的角色
        if (StrUtil.isNotEmpty(defectInfoDTO.getClinicDoctorRoleId()))
        {
            Role clinicDoctorRole = baseQuery.findRoleById(Long.parseLong(defectInfoDTO.getClinicDoctorRoleId()));
            ActParticipation part = getActFactory().newActParticipation();
            part.setTypeCode(ParticipationType.INF);
            addParticipation(clinicDoctorRole, part);
        }
        if (StrUtil.isNotEmpty(defectInfoDTO.getMqaDoctorRoleId()))
        {
            Role mqaDoctorRole = baseQuery.findRoleById(Long.parseLong(defectInfoDTO.getMqaDoctorRoleId()));
            ActParticipation part = getActFactory().newActParticipation();
            part.setTypeCode(ParticipationType.CSF);
            addParticipation(mqaDoctorRole, part);
        }
        if (StrUtil.isNotEmpty(defectInfoDTO.getPatientRoleId()))
        {
            Role patientRole = baseQuery.findRoleById(Long.parseLong(defectInfoDTO.getPatientRoleId()));
            ActParticipation part = getActFactory().newActParticipation();
            part.setTypeCode(ParticipationType.SBJ);
            addParticipation(patientRole, part);
        }
        // 5、创建ControlAct关系
        ControlAct control = newControlAct(information);
        // 6、调用save方法
        save(control);
        defectInfoDTO.setId(information.getActId()+"");
        // 7、打印添加log消息 返回
        super.log.info("新增缺陷信息成功: ActId " + information.getActId());
        return this.getResultsDTO("新增模板成功", true, defectInfoDTO);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public ResultsDTO delDefectInfo(List defectInfoIds) throws Hl7Exception
    {
        if (ListUtil.isEmpty(defectInfoIds))
        {
            log.info("删除缺陷信息失败，defectInfoIds为空");
            return getResultsDTO("删除缺陷信息失败", false, null);
        }

        String defectInfoId = (String) defectInfoIds.get(0);
        Act information = baseQuery.findActByActId(Long.valueOf(defectInfoId));
        delete(information);

        log.info("删除缺陷信息，id " + defectInfoId);
        return getResultsDTO("删除缺陷信息", true, "");
    }

    @Override
    public ResultsDTO updateDefectInfo(DefectInfoDTO defectInfoDTO) throws Hl7Exception
    {
        // 1、判断defectInfoDTO是否为空，为空直接返回
        if (defectInfoDTO == null)
        {
            super.log.info("defectInfoDTO 为空", defectInfoDTO);
            return getResultsDTO("修改缺陷信息失败,缺陷信息为空", false, null);
        }
        // 2、查询一个缺陷动作
        Act information = baseQuery.findActByActId(Long.valueOf(defectInfoDTO.getId()));
        // 3、给缺陷动作赋值
        convertInformationFromDefectDTO(defectInfoDTO, information);
        // 4、加入参与到缺陷动作的角色
        modifyInformationPartcptnRole(defectInfoDTO, information);
        // 5、创建ControlAct关系
        // 无
        // 6、调用update方法
        update(information);
        // 7、打印添加log消息 返回
        super.log.info("修改缺陷信息成功: ActId " + information.getActId());
        return this.getResultsDTO("修改缺陷信息成功", true, information.getActId().toString());
    }

    @Override
    public ResultsDTO findDefectInfoListByClinicDoctorRoleId(String clinicDoctorRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicDoctorRoleId))
        {
            return this.getResultsDTO("临床医生为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(clinicDoctorRoleId, null, null, null, -1, -1);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            return this.getResultsDTO("该临床医生的缺陷信息查询成功", true, defectinfoList);
        }
        else
        {
            return this.getResultsDTO("找不到该临床医生的缺陷信息", true, null);
        }

    }

    @Override
    public ResultsDTO findDefectInfoListByClinicDoctorRoleId(String clinicDoctorRoleId, int pageNo, int pageSize) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicDoctorRoleId))
        {
            return this.getResultsDTO("临床医生为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(clinicDoctorRoleId, null, null, null, pageNo, pageSize);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            Long totalRecords = defectQueryLocal.findCountDefectInfoListByCond(clinicDoctorRoleId, null, null, null);
            return this.getResultsDTO("该临床医生的缺陷信息查询成功", true, defectinfoList, converPageDTO(pageNo,pageSize,totalRecords.intValue()));
        }
        else
        {
            return this.getResultsDTO("找不到该临床医生的缺陷信息", true, null);
        }
    }

    @Override
    public ResultsDTO findDefectInfoListByClinicWorkGroupRoleId(String clinicWorkGroupRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicWorkGroupRoleId))
        {
            return this.getResultsDTO("工作组为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, clinicWorkGroupRoleId, null, null, -1, -1);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            return this.getResultsDTO("该临床医生在某工作组的缺陷信息查询成功", true, defectinfoList);
        }
        else
        {
            return this.getResultsDTO("找不到该临床医生在某工作组的缺陷信息", true, null);
        }

    }

    @Override
    public ResultsDTO findDefectInfoListByClinicWorkGroupRoleId(String clinicWorkGroupRoleId, int pageNo, int pageSize) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicWorkGroupRoleId))
        {
            return this.getResultsDTO("工作组为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, clinicWorkGroupRoleId, null, null, pageNo, pageSize);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            Long totalRecords = defectQueryLocal.findCountDefectInfoListByCond(null, clinicWorkGroupRoleId, null, null);
            return this.getResultsDTO("该临床医生在某工作组的缺陷信息查询成功", true, defectinfoList, converPageDTO(pageNo,pageSize,totalRecords.intValue()) );
        }
        else
        {
            return this.getResultsDTO("找不到该临床医生在某工作组的缺陷信息", true, null);
        }
    }

    @Override
    public ResultsDTO findDefectInfoListByMqaDoctorRoleId(String mqaDoctorRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(mqaDoctorRoleId))
        {
            return this.getResultsDTO("质控医生为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, mqaDoctorRoleId, null, -1, -1);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            return this.getResultsDTO("该质控医生发出的缺陷信息查询成功", true, defectinfoList);
        }
        else
        {
            return this.getResultsDTO("找不到该质控医生发出的缺陷信息", true, null);
        }
    }

    @Override
    public ResultsDTO findDefectInfoListByMqaDoctorRoleId(String mqaDoctorRoleId, int pageNo, int pageSize) throws Hl7Exception
    {
        if (StrUtil.isEmpty(mqaDoctorRoleId))
        {
            return this.getResultsDTO("质控医生为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, mqaDoctorRoleId, null, pageNo, pageSize);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            Long totalRecords = defectQueryLocal.findCountDefectInfoListByCond(null, null, mqaDoctorRoleId, null);
            return this.getResultsDTO("该质控医生发出的缺陷信息查询成功", true, defectinfoList, converPageDTO(pageNo,pageSize,totalRecords.intValue()));
        }
        else
        {
            return this.getResultsDTO("找不到该质控医生发出的缺陷信息", true, null);
        }
    }

    @Override
    public ResultsDTO findDefectInfoListByPatientRoleId(String patientRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(patientRoleId))
        {
            return this.getResultsDTO("患者为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, null, patientRoleId, -1, -1);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            return this.getResultsDTO("该患者的缺陷信息查询成功", true, defectinfoList);
        }
        else
        {
            return this.getResultsDTO("找不到该患者的缺陷信息", true, null);
        }

    }

    @Override
    public ResultsDTO findDefectInfoListBypatientRoleId(String patientRoleId, int pageNo, int pageSize) throws Hl7Exception
    {
        if (StrUtil.isEmpty(patientRoleId))
        {
            return this.getResultsDTO("患者为空", true, null);
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, null, patientRoleId, pageNo, pageSize);
        List<DefectInfoDTO> defectinfoList = convertDefectInfoDTOListFromInformationList(informationList);
        if (ListUtil.isNotEmpty(defectinfoList))
        {
            Long totalRecords = defectQueryLocal.findCountDefectInfoListByCond(null, null, null, patientRoleId);
            return this.getResultsDTO("该患者的缺陷信息查询成功", true, defectinfoList, converPageDTO(pageNo,pageSize,totalRecords.intValue()));
        }
        else
        {
            return this.getResultsDTO("找不到该患者的缺陷信息", true, null);
        }
    }

    @Override
    public ResultsDTO findDefectInfoDetailById(String defectInfoId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(defectInfoId))
        {
            return this.getResultsDTO("动作Id为空", true, null);
        }
        Act act = defectQueryLocal.findInformationByActId(defectInfoId);
        if (act != null)
        {
            return this.getResultsDTO("该患者的缺陷信息查询成功", true, act);
        }
        else
        {
            return this.getResultsDTO("找不到缺陷信息", true, null);
        }
    }

    /**
     * 将DTO中的相关信息设置到Information中
     */
    private Act convertInformationFromDefectDTO(DefectInfoDTO defectInfoDTO, Act information) throws Hl7Exception
    {
        String dateStr = DateUtil.GetDateTime();
        if (null == defectInfoDTO || null == information)
            return null;

        // 缺陷分类名称
        if (!StrUtil.isEmpty(defectInfoDTO.getDefectTypeName()))
        {
            ST name = getDataTypeFactory().newST(defectInfoDTO.getDefectTypeName());
            information.setTitle(name);
        }

        // 缺陷信息
        if (StrUtil.isNotEmpty(defectInfoDTO.getDefectInfo()))
        {
            ED defectInfo = DataTypeUtil.getED(defectInfoDTO.getDefectInfo());
            information.setText(defectInfo);
        }

        // 状态编码
        if (StrUtil.isNotEmpty(defectInfoDTO.getDefectAcceptStatus()))
        {
            information.setStatusCode(DataTypeUtil.getCS(defectInfoDTO.getDefectAcceptStatus()));
        }
        // 质控人
        if (!StrUtil.isEmpty(defectInfoDTO.getMqaDoctorRoleId()))
        {
            information.setCreatedBy(Long.parseLong(defectInfoDTO.getMqaDoctorRoleId()));
            if( StrUtil.isMinusOne(defectInfoDTO.getCreationDate()) )
            {
                information.setCreationDate(DateUtil.getTimestamp(dateStr));
                defectInfoDTO.setCreationDate(dateStr);
                defectInfoDTO.setDefectSendTime(dateStr);
            }
            
        }

        // 最后修改人
        if (information.getActId() != null && information.getActId() != 0l && !StrUtil.isEmpty(defectInfoDTO.getClinicDoctorRoleId()))
        {
            information.setLastUpdatedBy(Long.parseLong(defectInfoDTO.getClinicDoctorRoleId()));
            if( StrUtil.isMinusOne(defectInfoDTO.getLastUpdateDate()) )
            {
                information.setLastUpdateDate(DateUtil.getTimestamp(dateStr));
            }
        }
        return information;
    }

    /**
     * 将Information列表转换到DTO列表中
     */
    private List<DefectInfoDTO> convertDefectInfoDTOListFromInformationList(List<Act> actList) throws Hl7Exception
    {
        List<DefectInfoDTO> defectInfoDTOList = new ArrayList<DefectInfoDTO>();
        if (ListUtil.isNotEmpty(actList))
        {
            for (Act act : actList)
            {
                DefectInfoDTO defectInfoDTO = convertDefectInfoDTOFromInformation(act, null);
                defectInfoDTOList.add(defectInfoDTO);
            }
        }
        return defectInfoDTOList;
    }

    /**
     * 将Information列表转换到DTO中
     */
    private DefectInfoDTO convertDefectInfoDTOFromInformationList(List<Act> actList) throws Hl7Exception
    {
        DefectInfoDTO defectInfoDTO = new DefectInfoDTO();
        if (ListUtil.isNotEmpty(actList))
        {
            defectInfoDTO.setDefecInfoNum(actList.size()+"");
            for (Act act : actList)
            {
                defectInfoDTO = convertDefectInfoDTOFromInformation(act, defectInfoDTO);
            }
        }
        else
        {
            defectInfoDTO.setDefecInfoNum("0");
        }
        return defectInfoDTO;
    }

    private DefectInfoDTO convertDefectInfoDTOFromInformation(Act act, DefectInfoDTO dto) throws Hl7Exception
    {
        boolean newFlag = false;
        if (dto == null)
        {
            newFlag = true;
            dto = new DefectInfoDTO();
        }
        String lastMQADate = null;
        dto.setCreationDate(DateUtil.getFormatTimestamp(act.getCreationDate(), "yyyy-MM-dd HH:mm:ss"));
        if( !newFlag ){
            if( StrUtil.isEmpty(lastMQADate))
            {
                lastMQADate = dto.getCreationDate();
            }
            if (StrUtil.isNotEmpty(dto.getCreationDate()) && dto.getCreationDate().compareTo(lastMQADate) > 0)
            {
                lastMQADate = dto.getCreationDate();
            }
        }
        if (ListUtil.isNotEmpty(act.getParticipations()))
        {
            for (ActParticipation p : act.getParticipations())
            {
                if (ParticipationType.CSF.equals(p.getTypecode()))
                {
                    dto.setMqaDoctorRoleId(p.getRoleparticipation().getRoleId() + "");
                    dto.setMqaDoctorName(p.getRole().getPlayerEntity().getNameByUse(EntityNameUse.L).formatted().literal().stringValue());
                }
                else if (ParticipationType.INF.equals(p.getTypecode()))
                {
                    dto.setClinicDoctorRoleId(p.getRoleparticipation().getRoleId() + "");
                    dto.setClinicDoctorName(p.getRole().getPlayerEntity().getNameByUse(EntityNameUse.L).formatted().literal().stringValue());
                }
                else if (ParticipationType.SBJ.equals(p.getTypecode()))
                {
                    dto.setPatientRoleId(p.getRoleparticipation().getRoleId() + "");
                    dto.setPatientName(p.getRole().getPlayerEntity().getNameByUse(EntityNameUse.L).formatted().literal().stringValue());
                    dto.setMedicalRecordNumber(p.getRole().getId(RoleIICode.ADMISSIONNO).extension().stringValue());
                    Role bedRole = patientEncounterQueryLocal.findBedRoleByPatientRoleId(p.getRole().getRoleId()+"");
                    if( bedRole != null ){
                        dto.setBedNo(bedRole.getPlayerEntity().getNameByUse(EntityNameUse.L).formatted().literal().stringValue());
                    }
                }
            }
        }
        dto.setId(act.getActId() + "");
        dto.setDefectInfo(act.getText().stringValue());
        dto.setDefectTypeCode(act.getCode().code().stringValue());
        dto.setDefectTypeName(act.getTitle().stringValue());
        dto.setDefectAcceptStatus(act.getStatusCode().code().stringValue());
        if( newFlag )
        {
            dto.setCreationDate(dto.getCreationDate());
            dto.setDefectSendTime(dto.getCreationDate());
        }
        else
        {
            dto.setCreationDate(lastMQADate);
            dto.setDefectSendTime(lastMQADate);
        }
        if("1".equals(dto.getDefectAcceptStatus()))
        {
            dto.setAcceptTime(DateUtil.getFormatTimestamp(act.getLastUpdateDate(), "yyyy-MM-dd HH:mm:ss"));
        }
        return dto;
    }

    @Override
    public DefectInfoDTO findDefectInfoByClinicDoctorRoleId(String clinicDoctorRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicDoctorRoleId))
        {
            return null;
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(clinicDoctorRoleId, null, null, null, -1, -1);
        DefectInfoDTO dto = convertDefectInfoDTOFromInformationList(informationList);
        if (dto != null)
        {
            return dto;
        }
        else
        {
            return null;
        }
    }

    @Override
    public DefectInfoDTO findDefectInfoByClinicWorkGroupRoleId(String clinicWorkGroupRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(clinicWorkGroupRoleId))
        {
            return null;
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, clinicWorkGroupRoleId, null, null, -1, -1);
        DefectInfoDTO dto = convertDefectInfoDTOFromInformationList(informationList);
        if (dto != null)
        {
            return dto;
        }
        else
        {
            return null;
        }
    }

    @Override
    public DefectInfoDTO findDefectInfoByMqaDoctorRoleId(String mqaDoctorRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(mqaDoctorRoleId))
        {
            return null;
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, mqaDoctorRoleId, null, -1, -1);
        DefectInfoDTO dto = convertDefectInfoDTOFromInformationList(informationList);
        if (dto != null)
        {
            return dto;
        }
        else
        {
            return null;
        }
    }

    @Override
    public DefectInfoDTO findDefectInfoByPatientRoleId(String patientRoleId) throws Hl7Exception
    {
        if (StrUtil.isEmpty(patientRoleId))
        {
            return null;
        }
        List<Act> informationList = defectQueryLocal.findDefectInfoListByCond(null, null, null, patientRoleId, -1, -1);
        DefectInfoDTO dto = convertDefectInfoDTOFromInformationList(informationList);
        if (dto != null)
        {
            return dto;
        }
        else
        {
            return null;
        }
    }

    private void modifyInformationPartcptnRole(DefectInfoDTO defectInfoDTO, Act act) throws Hl7Exception
    {
        if (StrUtil.isNotEmpty(defectInfoDTO.getClinicDoctorRoleId()))
        {
            List<ActParticipation> patcptns = act.getParticipations();
            if (ListUtil.isNotEmpty(patcptns))
            {
                for (ActParticipation patcptn : patcptns)
                {
                    if (patcptn.getTypecode().equals(ParticipationType.INF))
                    {
                        Role role = (Role) patcptn.getRoleparticipation();
                        if (defectInfoDTO.getClinicDoctorRoleId().equals(String.valueOf(role.getRoleId())))
                        {
                            // 临床医生
                            Role clinicDoctorRole = baseQuery.findRoleById(Long.valueOf(defectInfoDTO.getClinicDoctorRoleId()));
                            patcptn.setRoleparticipation(clinicDoctorRole);
                            super.update(patcptn);
                            log.info("修改临床医生成功");
                        }
                    }
                    else if (patcptn.getTypecode().equals(ParticipationType.CSF))
                    {
                        Role role = (Role) patcptn.getRoleparticipation();
                        if (defectInfoDTO.getMqaDoctorRoleId().equals(String.valueOf(role.getRoleId())))
                        {
                            // 质控医生
                            Role mqaDoctorRole = baseQuery.findRoleById(Long.valueOf(defectInfoDTO.getMqaDoctorRoleId()));
                            patcptn.setRoleparticipation(mqaDoctorRole);
                            super.update(patcptn);
                            log.info("修改质控医生成功");
                        }
                    }
                    else if (patcptn.getTypecode().equals(ParticipationType.SBJ))
                    {
                        Role role = (Role) patcptn.getRoleparticipation();
                        if (defectInfoDTO.getClinicDoctorRoleId().equals(String.valueOf(role.getRoleId())))
                        {
                            // 患者
                            Role patientRole = baseQuery.findRoleById(Long.valueOf(defectInfoDTO.getPatientRoleId()));
                            patcptn.setRoleparticipation(patientRole);
                            super.update(patcptn);
                            log.info("修改患者成功");
                        }
                    }
                }
            }
        }
    }
    
    private PageDTO converPageDTO(int pageNo,int pageSize,int totalRecord){
        PageDTO dto = new PageDTO();
        dto.setPageNo(pageNo);
        dto.setPageSize(pageSize);
        dto.setTotalRecord(totalRecord);
        return dto;
    }
}
